package
{
	import events.BuildingEvent;
	
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class BuildingSelector extends Sprite
	{
		private var buildingArr:Array = ["assets/pic1100101.png","assets/pic1100201.png",
			"assets/pic1100301.png"];
		
		public function BuildingSelector()
		{
			super();
			
			var g:Graphics = this.graphics;
			g.beginFill(0x336699,0.6);
			g.drawRoundRect(0,0,430,89,5,5);
			g.endFill();
			
			for(var i:int=0; i<buildingArr.length; i++)
			{
				var image:Image = new Image();
				this.addChild( image );
				image.loadImage( buildingArr[i] );
				
				image.x = 20 + 130 * i;
				image.y = 5 ;
				
				image.addEventListener(MouseEvent.CLICK, onImageClick);
			}
		}
		
		protected function onImageClick(event:MouseEvent):void
		{
			var image:Image = event.currentTarget as Image;
			trace( image.url );
			
			var evt:BuildingEvent = new BuildingEvent( BuildingEvent.SELECTED, image.url );
			this.dispatchEvent( evt );
			
			
		}		
		
	}
}